package document;

import java.awt.*;
import java.util.Hashtable;

/**
 * Created by Pavel Nikolaev
 */
public class Context {
    private String myDefaultFontName;
    private String myPreformattedFontName;
    private int[] myDefaultFontSizes;
    private int myListIndentWidth;
    private Dimension myDefaultImageSizes;
    private Font myDefaultFont;
    private Hashtable<AttributeSet, Font> myFonts;

    public Context() {
        this.myDefaultFontName = "Arial";
        this.myPreformattedFontName = "Courier";
        this.myDefaultFontSizes = new int[]{12, 16, 20, 24, 28, 32, 36};
        this.myListIndentWidth = 40;
        this.myDefaultImageSizes = new Dimension(50, 50);
        this.myDefaultFont = new Font(myDefaultFontName, 0, myDefaultFontSizes[0]);
        this.myFonts = new Hashtable<AttributeSet, Font>(20);
    }

    public Font getFont(AttributeSet attributeSet) {
        Font font = myFonts.get(attributeSet);
        if (font != null) return font;

        int style = 0;
        if (attributeSet.myBoldMode) style |= Font.BOLD;
        if (attributeSet.myItalicMode) style |= Font.ITALIC;
        String font_name = (attributeSet.myPreformattedMode) ?
                myPreformattedFontName :
                myDefaultFontName;
        int size = myDefaultFontSizes[attributeSet.mySizeLevel];
        font = new Font(font_name, style, size);
        myFonts.put(attributeSet, font);
        return font;
    }

    public Font getFont() {
        return myDefaultFont;
    }

    public int getListIndentWidth() {
        return myListIndentWidth;
    }

    public int getImageDefaultWidth() {
        return myDefaultImageSizes.width;
    }

    public int getImageDefaultHeight() {
        return myDefaultImageSizes.height;
    }

    public Color getHighlightColor() {
        return Color.BLUE;
    }

    public Color getBackgroundColor() {
        return Color.WHITE;
    }
}
